package com.sh.rpc.server.tcp;

import io.vertx.core.Vertx;
import io.vertx.core.net.NetSocket;

/**
 * 自定义的tcp客户端
 * @author sh
 */
public class VertxTcpClient {

    public void start(){
        Vertx vertx = Vertx.vertx();
        vertx.createNetClient().connect(9999, "localhost", result ->{
            if ( result.succeeded() ){
                System.out.println("connect to tcp server success");
                NetSocket socket = result.result();
                socket.write("hello tcp server, this is client");
                // 发送数据
                socket.handler(buffer ->{
                    System.out.println("收到DIY tcp服务器: " + buffer.toString());
                });
            }else {
                System.err.println("connect to tcp server failed");
            }
        });
    }

    public static void main(String[] args) {
        new VertxTcpClient().start();
    }



}
